
package com.lcy.servlet;

import com.lcy.entry.SmbmsUser;
import com.lcy.service.LoginService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.*;
import java.util.Collection;

public class LoginServlet extends HttpServlet {
    private Object Properties;
    private Object String;
    private java.sql.Connection Connection;
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("userName");
        System.out.println(name);
        String pwd = req.getParameter("userPwd");
        System.out.println(pwd);
        LoginService loginService = new LoginService();
        boolean isLogin = loginService.login(name,pwd);
        if(isLogin) {
            HttpSession session = req.getSession();
            session.setAttribute("userName", name);
            resp.sendRedirect("home.do");
        }else {
            resp.sendRedirect("login.jsp?error=1");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);

    }
}